package com.atao.baokede.mapper;

import com.atao.baokede.pojo.Merchant;
import com.atao.baokede.pojo.dto.MerchantDto2;
import org.apache.ibatis.annotations.*;

@Mapper
public interface MerchantMapper {
    // 根据商户名称查询商户信息
    @Select("select * from merchant where name = #{name}")
    Merchant findByName(String name);

    // 注册商户
    @Insert("insert into merchant(name,password, logo, description, province, city, district, detail, status, creater,balance, create_time) " +
            "values(#{name},#{password}, #{logo}, #{description}, #{province}, #{city},#{district}, #{detail}, #{status}, #{creater},#{balance}, now())")
    void register(Merchant merchant);

    // 获取商户信息
    @Select("select * from merchant where id = #{merchantId}")
    Merchant getMerchantInfo(Long merchantId);

    // 修改商户信息
    @Update("update merchant set name = #{dto.name}, description = #{dto.description}, province = #{dto.province}, city = #{dto.city}, district = #{dto.district}, detail = #{dto.detail}, update_time = now() where id = #{merchantId}")
    void update(@Param("dto") MerchantDto2 merchantDto2, Long merchantId);

    // 修改商户头像
    @Update("update merchant set logo = #{avatarUrl}, update_time = now() where id = #{merchantId}")
    void updateLogo(String avatarUrl, Long merchantId);

    // 修改商户密码
    @Update("update merchant set password = #{newPwd}, update_time = now() where id = #{merchantId}")
    void updatePwd(String newPwd, Long merchantId);

    // 根据用户id查询商户信息
    @Select("select * from merchant where creater = #{userId}")
    Merchant findByUserId(Long userId);
}
